package com.yanqu.road.entity.player;

import com.yanqu.road.entity.DataObject;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

public class UserPatrons extends DataObject {

	private long userId;

	private int patronsId;

	private int level;

	private int stageLv;

	private int breakLv;

	private List<UserPatronsSkill> skillList = new ArrayList<>();
	/**
	 * 缓存的凤魁技能
	 */
	private List<CombLeaderSkill> combLeaderSkillList = new ArrayList<>();
	/**
	 * 缓存的凤魁晋升id
	 */
	private int leaderPromotionId;
	/**
	 * 缓存的凤魁绑定的门客id
	 */
	private int leaderKeepSakePatronsId;
	/**
	 * 缓存门客赚钱能力
	 */
	private BigInteger ability = BigInteger.ZERO;
	/**
	 * 缓存未算加成前的基础赚钱能力
	 */
	private BigDecimal baseAbility = BigDecimal.ZERO;
	/**
	 * 缓存计算赚钱能力的参数
	 */
	private BigDecimal calcAbilityParam = BigDecimal.ZERO;
	/**
	 * 缓存赚钱能力千分比加成值
	 */
	private BigDecimal abilityAdditionRatio = BigDecimal.ZERO;
	/**
	 * 缓存门客资质
	 */
	private long qualification;
	/**
	 * 缓存商战减少积分损失效果
	 */
	private long tradeWarLoseScoreReduce;

	private BigInteger addAbility = BigInteger.ZERO;

	private BigInteger tradeWarAddEarnSpeed = BigInteger.ZERO;

	//盐场计算出玩家队伍加成后的赚速 ，临时计算不入库
	private BigInteger oreWarEarnSpeed = BigInteger.ZERO;

	private BigInteger currentBlood = BigInteger.ZERO;

	private BigInteger totalBlood = BigInteger.ZERO;
	/**
	 * 战斗加成
	 */
	private int battleAddition = 1000;

	/**
	 * 盐场战斗成，要算好技能加成传到跨服
	 */
	private int oreWarBattleAddition = 1000;

	private int skinId;
	/**
	 * 厨艺值
	 */
	private long cookExp;
	/**
	 * 百业经验值
	 */
	private long baiYeExp;

	/**
	 * 筹算经验值
	 */
	private long chouSuanExp;

	/**
	 * 晋升id
	 */
	private int promotionId;

	/**
	 * 授学经验
	 */
	private long teacherExp;

	/**
	 * 孙子增加的赚速
	 */
	private BigInteger grandChildSpeed = BigInteger.ZERO;

	/**
	 * 不入库 展示用
	 */
	private BigInteger showGrandSpeed = BigInteger.ZERO;
	private boolean isLinkageSwitch;			//联动切换

	/**
	 * 信物增加的资质
	 */
	private long keepSakeAddition;

	private int keepSakePatronsId;

	private int keepSakeTime;

	//道具加的资质
	private int itemAddQualification;

	private Map<Integer, UserPatronsContract> patronsContractMap = new ConcurrentHashMap<>();


	//总资质（附加信物加成）
    public long getTotalQualification() {
        return this.qualification + this.keepSakeAddition;
    }

	public long getCookExp() {
		return cookExp;
	}

	public void setCookExp(long cookExp) {
		if(this.cookExp != cookExp){
			this.cookExp = cookExp;
			setUpdateOption();
		}
	}

	private boolean unionTradeSend;         //商贸派遣

	private long resetTime;                 //重置时间

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		if (this.userId != userId) {
			this.userId = userId;
			setUpdateOption();
		}
	}

	public int getPatronsId() {
		return patronsId;
	}

	public void setPatronsId(int patronsId) {
		if (this.patronsId != patronsId) {
			this.patronsId = patronsId;
			setUpdateOption();
		}
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		if (this.level != level) {
			this.level = level;
			setUpdateOption();
		}
	}

	public int getStageLv() {
		return stageLv;
	}

	public void setStageLv(int stageLv) {
		if(this.stageLv != stageLv) {
			this.stageLv = stageLv;
			setUpdateOption();
		}
	}

	public int getBreakLv() {
		return breakLv;
	}

	public void setBreakLv(int breakLv) {
		if(this.breakLv != breakLv) {
			this.breakLv = breakLv;
			setUpdateOption();
		}
	}

	public BigInteger getAbility() {
		return ability;
	}

	public void setAbility(BigInteger ability) {
		if(!Objects.equals(this.ability, ability)) {
			this.ability = ability;
			setUpdateOption();
		}
	}

	public BigDecimal getBaseAbility() {
		return baseAbility;
	}

	public void setBaseAbility(BigDecimal baseAbility) {
		if(!Objects.equals(this.baseAbility, baseAbility)) {
			this.baseAbility = baseAbility;
			setUpdateOption();
		}
	}

	public BigDecimal getCalcAbilityParam() {
		return calcAbilityParam;
	}

	public void setCalcAbilityParam(BigDecimal calcAbilityParam) {
		this.calcAbilityParam = calcAbilityParam;
	}

	public BigDecimal getAbilityAdditionRatio() {
		return abilityAdditionRatio;
	}

	public void setAbilityAdditionRatio(BigDecimal abilityAdditionRatio) {
		this.abilityAdditionRatio = abilityAdditionRatio;
	}

	public long getQualification() {
		return qualification;
	}

	public void setQualification(long qualification) {
		if(this.qualification != qualification) {
			this.qualification = qualification;
			setUpdateOption();
		}
	}

	public BigInteger getAddAbility() {
		return addAbility;
	}

	public void setAddAbility(BigInteger addAbility) {
		if(!Objects.equals(this.addAbility, addAbility)) {
			this.addAbility = addAbility;
			setUpdateOption();
		}
	}

	public BigInteger getTradeWarAddEarnSpeed() {
		return tradeWarAddEarnSpeed;
	}

	public void setTradeWarAddEarnSpeed(BigInteger tradeWarAddEarnSpeed) {
		if(!Objects.equals(this.tradeWarAddEarnSpeed, tradeWarAddEarnSpeed)) {
			this.tradeWarAddEarnSpeed = tradeWarAddEarnSpeed;
			setUpdateOption();
		}
	}

	public BigInteger getOreWarEarnSpeed() {
		return oreWarEarnSpeed;
	}

	public void setOreWarEarnSpeed(BigInteger oreWarEarnSpeed) {
		this.oreWarEarnSpeed = oreWarEarnSpeed;
	}

	//所有对原始技能表操作的用这个方法
	public List<UserPatronsSkill> getOriginalSkillList() {
		return skillList;
	}

	//所有取未删除技能的操作用这个方法
	public List<UserPatronsSkill> getSkillList() {
		List<UserPatronsSkill> tmpsSkillList =new ArrayList<>(skillList);
		List<UserPatronsSkill> resultSkillList = new ArrayList<>();
		for (UserPatronsSkill userPatronsSkill : tmpsSkillList) {
			if (userPatronsSkill.getIsDelete() == 0) {
				resultSkillList.add(userPatronsSkill);
			}
		}

		for (CombLeaderSkill leaderSkill : combLeaderSkillList) {
			resultSkillList.add(leaderSkill.parseToUserPatronsSkill());
		}
		return resultSkillList;
	}

	public void setSkillList(List<UserPatronsSkill> skillList) {
		this.skillList = skillList;
	}

	public UserPatronsSkill getPatronsSkill(int type, int skillId){
		if(null != getSkillList()) {
			List<UserPatronsSkill> tempSkillList = new ArrayList<>(getSkillList());
			for (UserPatronsSkill userPatronsSkill : tempSkillList){
				if(userPatronsSkill.getType() == type && userPatronsSkill.getSkillId() == skillId){
					return userPatronsSkill;
				}
			}
		}
		return null;
	}

	public UserPatronsSkill getPatronsSkill(int skillId){
		if(null != getSkillList()) {
			List<UserPatronsSkill> tempSkillList = new ArrayList<>(getSkillList());
			for (UserPatronsSkill userPatronsSkill : tempSkillList){
				if(userPatronsSkill.getSkillId() == skillId){
					return userPatronsSkill;
				}
			}
		}
		return null;
	}

	public boolean isContainsSkill(int type, int skillId){
		UserPatronsSkill userPatronsSkill = getPatronsSkill(type, skillId);
		return null != userPatronsSkill;
	}
	//不需判断是否被删除的技能的添加方法
	public void addSkill(UserPatronsSkill userPatronsSkill){
		skillList.add(userPatronsSkill);
	}

	public BigInteger getCurrentBlood() {
		return currentBlood;
	}

	public void setCurrentBlood(BigInteger currentBlood) {
		this.currentBlood = currentBlood;
	}

	public BigInteger getTotalBlood() {
		return totalBlood;
	}

	public void setTotalBlood(BigInteger totalBlood) {
		this.totalBlood = totalBlood;
	}

	public int getBattleAddition() {
		return battleAddition;
	}

	public void setBattleAddition(int battleAddition) {
		this.battleAddition = battleAddition;
	}

	public int getOreWarBattleAddition() {
		return oreWarBattleAddition;
	}

	public void setOreWarBattleAddition(int oreWarBattleAddition) {
		this.oreWarBattleAddition = oreWarBattleAddition;
	}

	public int getSkinId() {
		return skinId;
	}

	public void setSkinId(int skinId) {
		if (this.skinId != skinId) {
			this.skinId = skinId;
			setUpdateOption();
		}

	}

	public boolean isUnionTradeSend() {
		return unionTradeSend;
	}

	public void setUnionTradeSend(boolean unionTradeSend) {
		if(this.unionTradeSend != unionTradeSend) {
			this.unionTradeSend = unionTradeSend;
			setUpdateOption();
		}
	}

	public long getResetTime() {
		return resetTime;
	}

	public void setResetTime(long resetTime) {
		if(this.resetTime != resetTime) {
			this.resetTime = resetTime;
			setUpdateOption();
		}
	}


	/**
	 * 因为多了凤魁系统,拿实际的晋升id,要去getShowPromotionId()
	 * @return
	 */
	public int getPromotionId() {
		return promotionId;
	}

	public void setPromotionId(int promotionId) {
		if (this.promotionId != promotionId) {
			this.promotionId = promotionId;
			setUpdateOption();
		}
	}

	/**
	 * 仅用于战斗使用(注意资质)
	 */
	public UserPatrons cloneUserPatrons() {
		UserPatrons copyUserPatrons = new UserPatrons();
		copyUserPatrons.setUserId(userId);
		copyUserPatrons.setPatronsId(patronsId);
		copyUserPatrons.setStageLv(stageLv);
		copyUserPatrons.setBreakLv(breakLv);
		copyUserPatrons.setLevel(level);
		copyUserPatrons.setAbility(ability);
		copyUserPatrons.setQualification(getTotalQualification());
		copyUserPatrons.setSkillList(clonePatronsSkill());
		copyUserPatrons.setCurrentBlood(currentBlood);
		copyUserPatrons.setTotalBlood(totalBlood);
		copyUserPatrons.setSkinId(skinId);
		copyUserPatrons.setOreWarBattleAddition(oreWarBattleAddition);
		copyUserPatrons.setPromotionId(promotionId);
		copyUserPatrons.setTeacherExp(teacherExp);
		copyUserPatrons.setGrandChildSpeed(grandChildSpeed);
		return copyUserPatrons;
	}

	private List<UserPatronsSkill> clonePatronsSkill(){
		List<UserPatronsSkill> copySkillList = new ArrayList<>();
		if(null != getSkillList()){
			List<UserPatronsSkill> tempSkillList = new ArrayList<>(getSkillList());
			for(UserPatronsSkill skill : tempSkillList){
				UserPatronsSkill copySkill = skill.cloneUserPatronsSkill();
				copySkillList.add(copySkill);
			}
		}
		return copySkillList;
	}

	public long getBaiYeExp() {
		return baiYeExp;
	}

	public void setBaiYeExp(long baiYeExp) {
		if (this.baiYeExp != baiYeExp) {
			this.baiYeExp = baiYeExp;
			setUpdateOption();
		}
	}

	public long getTradeWarLoseScoreReduce() {
		return tradeWarLoseScoreReduce;
	}

	public void setTradeWarLoseScoreReduce(long tradeWarLoseScoreReduce) {
		if (this.tradeWarLoseScoreReduce != tradeWarLoseScoreReduce) {
			this.tradeWarLoseScoreReduce = tradeWarLoseScoreReduce;
			setUpdateOption();
		}
	}

	public long getChouSuanExp() {
		return chouSuanExp;
	}

	public void setChouSuanExp(long chouSuanExp) {
		if(this.chouSuanExp != chouSuanExp){
			this.chouSuanExp = chouSuanExp;
			setUpdateOption();
		}
	}

	public long getTeacherExp() {
		return teacherExp;
	}

	public void setTeacherExp(long teacherExp) {
		if (!Objects.equals(this.teacherExp, teacherExp)) {
			this.teacherExp = teacherExp;
			setUpdateOption();
		}
	}

	public BigInteger getGrandChildSpeed() {
		return grandChildSpeed;
	}

	public void setGrandChildSpeed(BigInteger grandChildSpeed) {
		if (!Objects.equals(this.grandChildSpeed, grandChildSpeed)) {
			this.grandChildSpeed = grandChildSpeed;
			setUpdateOption();
		}
	}

	public BigInteger getShowGrandSpeed() {
		return showGrandSpeed;
	}

	public UserPatrons setShowGrandSpeed(BigInteger showGrandSpeed) {
		this.showGrandSpeed = showGrandSpeed;
		return this;
	}

	public boolean isLinkageSwitch() {
		return isLinkageSwitch;
	}

	public void setLinkageSwitch(boolean linkageSwitch) {
		if(this.isLinkageSwitch != linkageSwitch) {
			isLinkageSwitch = linkageSwitch;
			setUpdateOption();
		}
	}

	public long getKeepSakeAddition() {
		return keepSakeAddition;
	}

	public void setKeepSakeAddition(long keepSakeAddition) {
		if(this.keepSakeAddition != keepSakeAddition) {
			this.keepSakeAddition = keepSakeAddition;
			setUpdateOption();
		}
	}

	public int getKeepSakePatronsId() {
		return keepSakePatronsId;
	}

	public void setKeepSakePatronsId(int keepSakePatronsId) {
		if(this.keepSakePatronsId != keepSakePatronsId) {
			this.keepSakePatronsId = keepSakePatronsId;
			setUpdateOption();
		}
	}

	public int getKeepSakeTime() {
		return keepSakeTime;
	}

	public void setKeepSakeTime(int keepSakeTime) {
		if(this.keepSakeTime != keepSakeTime) {
			this.keepSakeTime = keepSakeTime;
			setUpdateOption();
		}
	}

	public int getItemAddQualification() {
		return itemAddQualification;
	}

	public void setItemAddQualification(int itemAddQualification) {
		this.itemAddQualification = itemAddQualification;
		setUpdateOption();
	}

	public void addItemAddQualification(int itemAddQualification) {
		this.itemAddQualification += itemAddQualification;
		setUpdateOption();
	}

	public Map<Integer, UserPatronsContract> getPatronsContractMap() {
		return patronsContractMap;
	}

	public void setPatronsContractMap(Map<Integer, UserPatronsContract> patronsContractMap) {
		this.patronsContractMap = patronsContractMap;
	}

	public List<CombLeaderSkill> getCombLeaderSkillList() {
		return combLeaderSkillList;
	}

	public void setCombLeaderSkillList(List<CombLeaderSkill> combLeaderSkillList) {
		this.combLeaderSkillList = combLeaderSkillList;
	}

	public int getLeaderPromotionId() {
		return leaderPromotionId;
	}

	public void setLeaderPromotionId(int leaderPromotionId) {
		this.leaderPromotionId = leaderPromotionId;
	}

	/**
	 * 展示的晋升id
	 * @return
	 */
	public int getShowPromotionId() {
		if (leaderPromotionId > 0) {
			return leaderPromotionId;
		}
		return promotionId;
	}

	public int getLeaderKeepSakePatronsId() {
		return leaderKeepSakePatronsId;
	}

	public void setLeaderKeepSakePatronsId(int leaderKeepSakePatronsId) {
		this.leaderKeepSakePatronsId = leaderKeepSakePatronsId;
	}

	/**
	 * 展示的绑定门客id
	 */
	public int getShowKeepSakePatronsId() {
		if (leaderKeepSakePatronsId > 0) {
			return leaderKeepSakePatronsId;
		}
		return keepSakePatronsId;
	}

	public int getCombLeaderSkillLv(int skillId) {
		for (CombLeaderSkill leaderSkill : combLeaderSkillList) {
			if (leaderSkill.getId() == skillId) {
				return leaderSkill.getLv() + leaderSkill.getSkinLv();
			}
		}
		return 0;
	}

}
